package com.yssoft.controller.supervise;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.yssoft.entity.core.TArea;
import com.yssoft.entity.core.TEnterprise;
import com.yssoft.entity.core.TEnterpriseLicence;
import com.yssoft.service.core.AreaService;
import com.yssoft.service.core.EnterpriseService;

/**
 * @类名称: WarningEnterpriseController
 * @类描述: 企业证照预警控制器
 * @作者: 王永宁
 * @创建时间:2018年6月8日 下午17:21:50
 */
@Controller
@RequestMapping("/warning/warningEnterprise")
public class WarningEnterpriseController {

    @Resource
    private EnterpriseService enterpriseService;
    
	@Resource
	private AreaService areaService;
	
    /**
     * 跳转到企业证照预警页面
     * @return
     */
    @RequestMapping("/enterprisePage")
    public String enterprisePage() {
        return "supervise/warning/enterpriseList";
    }
    
    /**
     * 获取企业证照预警数据
     * 王永宁
     * @param page
     * @param limit
     * @return
     */
    @RequestMapping("/findEnterprisePage")
    @ResponseBody
    public JSONObject findEnterprisePage(@RequestParam(name = "page", defaultValue = "0") int page, @RequestParam(name = "limit", defaultValue = "10") int limit, String yy,String sc) {
        JSONObject jsonObject = enterpriseService.queryWarningEnterprisePage(page, limit,yy,sc);
        return jsonObject;
    }

    /**
     * 跳转详细界面
     * @param model
     * @param enterpriseId
     * @return
     */
    @RequestMapping("/enterpriseDetail")
    public String enterpriseDetail(Model model, String enterpriseId){
    	if(enterpriseId!=null && !"".equals(enterpriseId)){
    		/*查询企业信息*/
    		TEnterprise tenterprise = enterpriseService.queryEnterpriseById(Integer.parseInt(enterpriseId));
        	model.addAttribute("tenterprise", tenterprise);
        	/*查询区域信息*/
        	TArea area = areaService.queryAreaById(tenterprise.getT_a_id());
        	if(area != null){
        		model.addAttribute("areaname", area.getName());
        	}
        	/*企业证照信息1-生产许可证*/
        	TEnterpriseLicence licence1 = enterpriseService.queryLicenceByCode(Integer.parseInt(enterpriseId),"1");
        	model.addAttribute("licence1", licence1);
        	/*企业证照信息2-营业执照*/
        	TEnterpriseLicence licence2 = enterpriseService.queryLicenceByCode(Integer.parseInt(enterpriseId),"2");
        	model.addAttribute("licence2", licence2);
    	}
    	return "supervise/warning/enterpriseDetail";
    }

}
